package com.xiaohong.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.goods.dao.BrandMapper;
import com.xiaohong.goods.pojo.Brand;
import com.xiaohong.goods.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;


    /**
     * 条件+分页查询Brand
     * @param brand 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Brand> findPage(Brand brand, int page, int size){
        // 构建查询条件
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<Brand>(brand);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return brandMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Brand
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Brand> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return brandMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Brand
     * @param brand
     * @return
     */
    @Override
    public List<Brand> findList(Brand brand){
        // 构建查询条件
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<Brand>(brand);
        // 查询数据
        return brandMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Brand
     * @param id
     */
    @Override
    public void delete(int id){
        brandMapper.deleteById(id);
    }

    /**
     * 根据ID修改Brand
     * @param brand
     */
    @Override
    public void update(Brand brand){
        brandMapper.updateById(brand);
    }

    /**
     * 增加Brand
     * @param brand
     */
    @Override
    public void add(Brand brand){
        brandMapper.insert(brand);
    }

    /**
     * 根据ID查询Brand
     * @param id
     * @return
     */
    @Override
    public Brand findById(int id){
        return  brandMapper.selectById(id);
    }

    /**
     * 查询全部Brand数据
     * @return
     */
    @Override
    public List<Brand> findAll() {
        return brandMapper.selectList(null);
    }
}
